package com.sunyur.tailor.channel.web.outer.protocol.dto;

import com.sunyur.tailor.channel.service.inner.protocol.param.CreateProtocolParam;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @Author: rongniu
 * @Description: 创建协议请求实体
 * @Date: 2021/7/15 9:38
 * @Param:
 * @return:
 **/
@Data
public class CreateProtocolDTO implements Serializable {
    @NotEmpty(message = "协议编号不能为空")
    @Size(max = 45, message = "协议编号长度不能超过45")
    private String protocolCode;

    @Size(max = 50, message = "合同编号长度不能超过50")
    private String contractCode;

    @NotEmpty(message = "协议名称不能为空")
    @Size(max = 100, message = "协议名称长度不能超过100")
    private String protocolName;

    @Size(max = 50, message = "合同名称长度不能超过50")
    private String contractName;

    @NotEmpty(message = "采购员编码不能为空")
    @Size(max = 50, message = "采购员编码长度不能超过50")
    private String buyerCode;

    @NotEmpty(message = "采购组织编码不能为空")
    @Size(max = 45, message = "采购组织编码长度不能超过45")
    private String orgCode;

    @NotNull(message = "采购商公司主体编码集合不能为空")
    @Size(max = 1, message = "采购商公司主体编码集合长度不能超过1")
    private List<@NotEmpty(message = "采购商公司主体编码不能为空") @Size(max = 50, message = "采购商公司主体编长度不能超过50")String> companySubjectCodes;

    @NotNull(message = "定价方式不能为空")
    @Range(max = 2, min = 1, message = "定价方式不在1~2范围内")
    private Integer pricingMethod;

    @NotEmpty(message = "供应商编码不能为空")
    @Size(max = 45, message = "供应商编码长度不能超过45")
    private String supplierCode;

    @NotEmpty(message = "统一社会信用代码不能为空")
    @Size(max = 30, message = "统一社会信用代码长度不能超过30")
    private String supplierCreditCode;

    @NotNull(message = "交易方式不能为空")
    @Range(max = 3, min = 1, message = "交易方式不在1~3范围内")
    private Integer tradeMethod;

    @NotNull(message = "付款方式不能为空")
    @Range(max = 3, min = 1, message = "付款方式不在1~3范围内")
    private Integer paymentMethod;

    @Size(max = 500, message = "备注长度不能超过500")
    private String remark;

    @NotNull(message = "协议有效期开始时间不能为空")
    private Long protocolValidityBegin;

    @NotNull(message = "协议有效期结束时间不能为空")
    private Long protocolValidityEnd;

    @NotNull(message = "协议状态不能为空")
    @Range(max = 10, min = 0, message = "协议状态不在0~10范围内")
    private Integer protocolStatus;

    @NotNull(message = "运费类型不能为空")
    @Range(max = 1, min = 0, message = "运费类型不在0~1范围内")
    private Integer freightType;

    @NotNull(message = "协议行总数不能为空")
    @Max(value = 500, message = "协议行总数不能大于500行")
    private Integer itemTotal;

    @NotNull(message = "结算周期不能为空")
    @Range(max = 4, min = 1, message = "结算周期不在1~4范围内")
    private Integer settlementCycle;

    @NotNull(message = "业务模式类型不能为空")
    @Range(max = 2, min = 0, message = "业务模式类型不在0~2范围内")
    private Integer businessType;

    @Valid
    @NotNull(message = "协议行不能为空")
    private List<CreateProtocolDTO.ProtocolItems> protocolItems;

    @Data
    public static class ProtocolItems implements Serializable {

        @NotEmpty(message = "外部协议行主键不能为空")
        @Size(max = 45, message = "外部协议行主键长度不能超过45")
        private String outerProtocolItemId;

        @Size(max = 20, message = "品牌名称长度不能超过20")
        private String brandName;

        @Size(max = 1000, message = "行备注长度不能超过1000")
        private String itemRemark;

        @NotNull(message = "协议行有效期开始时间不能为空")
        private Long itemValidityBegin;

        @NotNull(message = "协议行有效期结束时间不能为空")
        private Long itemValidityEnd;

        @Size(max = 50, message = "采购名称长度不能超过50")
        private String itemBuyer;

        @NotEmpty(message = "物料编码不能为空")
        @Size(max = 45, message = "物料编码长度不能超过45")
        private String materielCode;

        @NotNull(message = "价格类型不能为空")
        @Range(max = 3, min = 1, message = "价格类型不在1~3范围内")
        private Integer priceType;

        @Range(max = 1, min = 0, message = "二次定价不在0~1范围内")
        private Integer secondPricing;

        @NotNull(message = "协议行类型不能为空")
        @Range(max = 1, min = 0, message = "协议行类型不在0~1范围内")
        private Integer protocolItemType;

        @Max(value = 11, message = "采购额上限不能超过11位")
        private Integer amountUpperLimit;

        @Max(value = 11, message = "交期上限不能超过11位")
        private Integer deliveryDate;

        @Valid
        @NotNull(message = "送货地区不能为空")
        private List<CreateProtocolDTO.ProtocolItems.DeliveryAreaList> deliveryAreaList;

        @Data
        public static class DeliveryAreaList implements  Serializable{

            @NotEmpty(message = "省编码不能为空")
            @Size(max = 20, message = "省编码长度不能超过20")
            private String provinceCode;

            @NotEmpty(message = "省名称不能为空")
            @Size(max = 50, message = "省名称长度不能超过50")
            private String provinceName;

            @NotEmpty(message = "城市编码不能为空")
            @Size(max = 20, message = "城市编码长度不能超过20")
            private String cityCode;

            @NotEmpty(message = "城市名称不能为空")
            @Size(max = 50, message = "城市名称长度不能超过50")
            private String cityName;
        }

        @Size(max = 200, message = "描述长度不能超过200")
        private String describeMsg;

        /**
         * 浮动折扣价格协议该模型不需要
         */
        @Valid
        private CreateProtocolDTO.ProtocolItems.PriceRule priceRule;

        @Data
        public static class PriceRule implements Serializable{

            @NotNull(message = "税点不能为空")
            @Digits(integer = 10, fraction = 5, message = "税点整数位不能超过10位，小数位不能超过5位")
            private BigDecimal taxPoint;

            @NotEmpty(message = "税点编码不能为空")
            @Size(max = 45, message = "税点编码长度不能超过45")
            private String taxCode;

            @NotNull(message = "起定量不能为空")
            @Digits(integer = 15, fraction = 5, message = "起定量整数位不能超过15位，小数位不能超过5位")
            private BigDecimal startQuantity;

            @Digits(integer = 15, fraction = 5, message = "参考价整数位不能超过15位，小数位不能超过5位")
            private BigDecimal referencePrice;

            /**
             * 区域定价模型
             */
            @Valid
            private List<CreateProtocolDTO.ProtocolItems.PriceRule.RegionPriceList> regionPriceList;

            @Data
            public static class RegionPriceList implements Serializable{
                /**
                 * 区域
                 */
                @Valid
                private List<CreateProtocolDTO.ProtocolItems.PriceRule.RegionPriceList.regionList> regionList;

                @Data
                public static class regionList implements  Serializable{
                    @NotEmpty(message = "省编码不能为空")
                    @Size(max = 20, message = "省编码长度不能超过20")
                    private String provinceCode;

                    @NotEmpty(message = "省名称不能为空")
                    @Size(max = 50, message = "省名称长度不能超过50")
                    private String provinceName;

                    @NotEmpty(message = "城市编码不能为空")
                    @Size(max = 20, message = "城市编码长度不能超过20")
                    private String cityCode;

                    @NotEmpty(message = "城市名称不能为空")
                    @Size(max = 50, message = "城市名称长度不能超过50")
                    private String cityName;
                }

                /**
                 * 价格
                 */
                @Valid
                private List<CreateProtocolDTO.ProtocolItems.PriceRule.RegionPriceList.PriceList> priceList;

                @Data
                public static class PriceList implements  Serializable{

                    @NotNull(message = "协议价(含税)不能为空")
                    @Digits(integer = 20, fraction = 10, message = "协议价(含税)整数位不能超过20位，小数位不能超过10位")
                    private BigDecimal price;

                    @NotNull(message = "未税价（元）不能为空")
                    @Digits(integer = 20, fraction = 10, message = "未税价（元）整数位不能超过20位，小数位不能超过10位")
                    private BigDecimal untaxedPrice;

                    @Digits(integer = 10, fraction = 2, message = "阶梯起订起始量（阶梯价必填）整数位不能超过10位，小数位不能超过2位")
                    private BigDecimal startStepQuantity;

                    @Digits(integer = 10, fraction = 2, message = "阶梯起订截止量（阶梯价必填）整数位不能超过10位，小数位不能超过2位")
                    private BigDecimal endStepQuantity;
                }
            }
        }

        @Size(max = 45, message = "质保期长度不能超过45")
        private String qualityAssurancePeriod;

        @NotNull(message = "协议行操作类型不能为空")
        @Range(max = 3, min = 1, message = "协议行操作类型不在1~3范围内")
        private Integer operateType;
    }

    @Size(max = 100, message = "操作人编码长度不能超过100")
    private String operatorCode;

    @NotNull(message = "发票类型不能为空")
    @Range(max = 2, min = 1, message = "发票类型不在1~2范围内")
    private Integer invoiceType;

    @Size(max = 40, message = "运费规则编码长度不能超过40")
    private String freightRuleCode;

    @NotEmpty(message = "币种编码不能为空")
    @Size(max = 40, message = "币种编码长度不能超过40")
    private String currencyCode;

    @NotEmpty(message = "外部付款条款编码不能为空")
    @Size(max = 50, message = "外部付款条款编码长度不能超过50")
    private String outsidePaymentClauseCode;

    /**
     * 付款条款详情
     */
    @Valid
    private List<CreateProtocolDTO.SettlementRules> settlementRules;

    @Data
    public static class SettlementRules implements Serializable {
        @Size(max = 50, message = "付款条款行编码长度不能超过50")
        private String paymentClauseItemCode;

        @NotNull(message = "预付款不能为空")
        @Range(max = 1, min = 0, message = "预付款不在0~1范围内")
        private Integer prepayment;

        @NotEmpty(message = "付款阶段编码不能为空")
        @Size(max = 50, message = "付款阶段编码长度不能超过50")
        private String paymentStageCode;

        @NotEmpty(message = "付款阶段名称不能为空")
        @Size(max = 50, message = "付款阶段名称长度不能超过50")
        private String paymentStageName;

        @Size(max = 200, message = "备注长度不能超过200")
        private String remark;
    }

    @Size(max = 60, message = "采购组编码长度不能超过60")
    private String paymentStageName;

    /**
     * 协议文本附件
     */
    @Valid
    private List<CreateProtocolDTO.ProtocolTextFileList> protocolTextFileList;

    @Data
    public static class ProtocolTextFileList implements Serializable {
        @Size(max = 50, message = "文件名称长度不能超过50")
        private String name;

        @Size(max = 60, message = "文件路径长度不能超过60")
        private String url;
    }
}
